package middleware

import (
	"context"
	"net/http"
)

type AuthTokenMiddleware struct {
}

func NewAuthTokenMiddleware() *AuthTokenMiddleware {
	return &AuthTokenMiddleware{}
}

func (m *AuthTokenMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		//token := r.Header.Get("token")
		//if token == "" {
		//	httpx.OkJsonCtx(r.Context(), w, &types.ApiResponse{
		//		Code: 0,
		//		Msg:  "token为空",
		//		Data: nil,
		//	})
		//	return
		//}
		//var payload string
		//if !pkg.ParseJwtToken(app_config.AppConf.JwtConfig.AccessKey, token, &payload) {
		//	httpx.OkJsonCtx(r.Context(), w, &types.ApiResponse{
		//		Code: 0,
		//		Msg:  "token错误",
		//		Data: nil,
		//	})
		//	return
		//}
		payload := "1"
		value := context.WithValue(r.Context(), "uid", payload)
		/*
			从令牌中解析出来的有效载荷（可能是用户ID或其他用户相关信息）。这个有效载荷被存储在上下文（context）中，键名为"uid"
		*/
		next(w, r.WithContext(value))
	}
}
